package com.ocgs.code.dao.impl;

import com.ocgs.base.core.exception.BaseDAOException;
import com.ocgs.code.dao.CodeDAO;
import com.ocgs.code.mapper.CodeMapper;
import com.ocgs.code.model.Code;
import com.ocgs.code.model.CodeKey;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bryant
 * Date: 10/21/12
 * Time: 3:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class CodeDAOImpl implements CodeDAO {

    private SqlSessionTemplate sqlSessionTemplate;

    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }


    public int deleteByPrimaryKey(CodeKey codeKey) throws BaseDAOException {

        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).deleteByPrimaryKey(codeKey);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }


    public int insert(Code record) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).insert(record);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }

    }

    public int insertSelective(Code record) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).insert(record);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }


    public Code selectByPrimaryKey(CodeKey codeKey) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).selectByPrimaryKey(codeKey);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }


    public int updateByPrimaryKeySelective(Code record) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).updateByPrimaryKeySelective(record);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }


    public int updateByPrimaryKey(Code record) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).updateByPrimaryKey(record);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }

    public List<Code> findAllCode(Code record) throws BaseDAOException {
        try {
            return sqlSessionTemplate.getMapper(CodeMapper.class).getAllCode(record);
        } catch (Exception e) {
            throw new BaseDAOException(e);
        }
    }
}
